#ifndef CUSTOMER_CPP
#define CUSTOMER_CPP

#include "customer.h"

customer::customer(){
	
	//Pre  Cons: None.
	//Post Cons: All data intialized to zero.

	fName  = "";
	lName  = "";
	arrive = 0;
	depart = 0;
	items  = 0;
	
	contest       = false;
	contestDepart = 0;
	contestArrive = 0;
	
	deli       = false;
	deliArrive = 0;
	deliDepart = 0;
	
	doneShopping = 0;
	
	payType    = CASH;
	lineType   = RC;
	lineArrive = 0;
	lineDepart = 0;
}

customer::customer(const customer& B){
	
	//Pre  Cons: Takes one const customer&.
	//Post Cons: Copys constructor.
	
        fName  = B.fName;
        lName  = B.lName;
        arrive = B.arrive;
        depart = B.depart;
        items  = B.items;

        contest       = B.contest;
        contestDepart = B.contestDepart;
        contestArrive = B.contestArrive;

        deli       = B.deli;
        deliArrive = B.deliArrive;
        deliDepart = B.deliDepart;
	
	doneShopping = B.doneShopping;

        payType    = B.payType;
        lineType   = B.lineType;
        lineArrive = B.lineArrive;
        lineDepart = B.lineDepart;

	
}

void customer::operator=(const customer& B){

        //Pre  Cons: Takes one one  customer&.
        //Post Cons: Copys B to this object.

        fName  = B.fName;
        lName  = B.lName;
        arrive = B.arrive;
        depart = B.depart;
        items  = B.items;

        contest       = B.contest;
        contestDepart = B.contestDepart;
        contestArrive = B.contestArrive;

        deli       = B.deli;
        deliArrive = B.deliArrive;
        deliDepart = B.deliDepart;

	doneShopping = B.doneShopping;

        payType    = B.payType;
        lineType   = B.lineType;
        lineArrive = B.lineArrive;
        lineDepart = B.lineDepart;        
}

//Getters and Setters
//All times will be given and expected in seconds.
//Assume operation by name.

void   customer::setLName(string name){lName = name;}
string customer::getLName(){return lName;}
void   customer::setFName(string name){fName = name;}
string customer::getFName(){return fName;}
string customer::getName(){return fName+" "+lName;}

void   customer::setArrive(int time){arrive = time;}
int    customer::getArrive(){return arrive;}
void   customer::setDepart(int time){depart = time;}
int    customer::getDepart(){return depart;}
void   customer::setItems(int number){items = number;}
int    customer::getItems(){return items;} 

void   customer::setContest(bool status){contest = status;}
bool   customer::getContest(){return contest;}
void   customer::setCArrive(int time){contestArrive = time;}
int    customer::getCArrive(){return contestArrive;}
void   customer::setCDepart(int time){contestDepart = time;}
int    customer::getCDepart(){return contestDepart;}

void   customer::setDeli(bool status){deli = status;}
bool   customer::getDeli(){return deli;}
void   customer::setDArrive(int time){deliArrive = time;}
int    customer::getDArrive(){return deliArrive;}
void   customer::setDDepart(int time){deliDepart = time;}
int    customer::getDDepart(){return deliDepart;}

void   customer::setDShopping(int time){doneShopping = time;}
int    customer::getDShopping(){return doneShopping;}

void   customer::setPType(PTYPE type){payType = type;}
PTYPE  customer::getPType(){return payType;}
void   customer::setLType(LTYPE type){lineType = type;}
LTYPE  customer::getLType(){return lineType;}
void   customer::setLArrive(int time){lineArrive = time;}
int    customer::getLArrive(){return lineArrive;}
void   customer::setLDepart(int time){lineDepart = time;}
int    customer::getLDepart(){return lineDepart;}

//Overloaded Operators and Friend Fuctions (Needed for STL list functions)

bool operator==(const customer& A, const customer& B){

	//Pre  Cons: Takes two const customer&.
	//Post Cons: If A and B do not match on all accounts
	//           returns false, otherwise returns true.

	if(A.fName != B.fName) 
		return(false);
	if(A.lName != B.lName) 
		return(false);
	if(A.arrive != B.arrive) 
		return(false);
	if(A.depart != B.depart) 
		return(false);
	if(A.items != B.items) 
		return(false);
	if(A.contest != B.contest)
		 return(false);
	if(A.contestDepart != B.contestDepart)
		 return(false);
	if(A.contestArrive != B.contestArrive) 
		return(false);
	if(A.deli != B.deli) 
		return(false);
	if(A.deliArrive != B.deliArrive) 
		return(false);
	if(A.deliDepart != B.deliDepart)
		return(false);
	if(A.doneShopping != B.doneShopping)
		return(false);
	if(A.payType != B.payType) 
		return(false);
	if(A.lineType != B.lineType) 
		return(false);
	if(A.lineArrive != B.lineArrive) 
		return(false);
	if(A.lineDepart != B.lineDepart) 
		return(false);

	return(true);
}

bool compare_names(const customer& A, const customer& B){

	//Pre  Cons: Takes two const customers&.
	//Post Cons: Creates two all lowercase strings from
	//           the customer objects' lName and fName.
	//           Returns true if the strings are equal
	//           or if aName comes before bName in
	//           alphabetical order otherwise returns
	//           false. Used in conjunction with STL list
	//           sort fuction to sort a list of customers
	//           by name.

	string aName = A.lName + A.fName;
	string bName = B.lName + B.fName;
	
	for(int i = 0; i < aName.length(); i++){
		if(aName[i] >= 'A' && aName[i] <= 'Z')
			aName[i] += 'a' - 'A';
	}
		
        for(int i = 0; i < bName.length(); i++){
                if(bName[i] >= 'A' && bName[i] <= 'Z')
                        bName[i] += 'a' - 'A';
        }
	
	if(aName.compare(bName) == 0)
		return(true);
	if(aName.compare(bName)  < 0)
		return(true);
	if(aName.compare(bName)  > 0)
		return(false);
}

bool compare_doneShopping(const customer& A, const customer& B){

        //Pre  Cons: Takes two const customers&.
        //Post Cons: Returns true if the first customer is
	//           done shopping before the second, returns
	//           false otherwise. Used in conjunction 
        //           with STL list's sort fuction to sort a  
        //           list of customers by when they are done
	//           shopping. 

	if(A.doneShopping < B.doneShopping)
		return(true);
	if(A.doneShopping > B.doneShopping)
		return(false);
}

#endif
